Re: [mockito] Mockito Configuration Loading

324 views
Skip to first unread message

Paul Richardson

unread,
Apr 16, 2013, 5:26:10 AM4/16/13
to moc...@googlegroups.com
Hi,

Sorry just discovered your reply in my other mailbox hence my tardiness ...

The method should be called once at the start of the test suite. For example, we have a test gatherer class [1] which looks at our entire eclipse workspace, finds all the test suites and executes them consecutively. Thus, the test gatherer first calls the setEnableClassCache(false) method before running any tests and this ensures there is no caching and therefore no class name clashes.

Thanks for getting back to me.

Regards

PGR


[1] https://github.com/Teiid-Designer/teiid-designer/blob/master/tests/org.teiid.designer.test/src/org/teiid/designer/test/AllPluginTests.java



On Sun, Mar 3, 2013 at 9:39 PM, Szczepan Faber <szcz...@gmail.com> wrote:
Hey Paul,

Sorry for late answer. I had some busy time after the New Year's :)

Let me understand the intention of the patch correctly. You cannot
drop your own IMockitoConfiguration due to some OSGI constraints. So
you're looking for a way to change the default mockito configuration
in a different way. Say we accept the patch with a setter method in a
DefaultMockitoConfiguration. When do you call this method?

Cheers!

On Mon, Jan 28, 2013 at 12:11 PM, Paul Richardson
<enig...@googlemail.com> wrote:
> Hi,
>
> Working on an eclipse project called Teiid Designer and we use mockito in
> our unit tests. In order to only have one mockito jar library in the
> codebase, we wrap the mockito-all jar as an OSGI plugin (essentially a jar
> with extra OSGI metadata). This means the plugin is loaded at the beginning
> of the set of unit tests then depended on by each executing test plugin.
>
> However, I have found a problem with the way objenesis caches mocked
> classes. Since the cache is keyed on the package/classname, two different
> classes that happen to share this key will conflict and the wrong one be
> used. This use case occurs in our codebase since we carry separate plugins
> of different versions of the same runtime client. The result is that tests
> based on one version of the runtime client cache its mocked classes then
> subsequent tests based on the second runtime client fail since attempts to
> mock its classes return the wrong mocked classes from the cache, resulting
> in ClassCastExceptions.
>
> The workaround is to turn the objensis cache off but due to eclipse's bundle
> class loading system it is impossible to derive a Configuration class, in a
> test plugin, that will get loaded by the mockito plugin's class loader. I
> have worked around this by adding an addition Configuration class in the
> mockito plugin itself but I have provided a patch to the
> DefaultMockitoConfiguration that will achieve the same result.
>
> Any chance this could be added into mocktio?
>
> Happy to provide further information if this is in any way confusing...
>
> Thanks
>
> PGR
>
>
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "mockito" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mockito+u...@googlegroups.com.
> To post to this group, send email to moc...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mockito?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Szczepan Faber
Principal engineer@gradleware
Lead@mockito

--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



Max Rydahl Andersen

unread,
May 8, 2013, 9:07:58 AM5/8/13
to moc...@googlegroups.com, enig...@googlemail.com
Any chance of this being fixed ? 

It is really disturbing having Mockito by default cache classes incorrectly and with no option than repackaging Mockito to make it work in osgi :(

/max

On Wednesday, April 24, 2013 8:03:05 PM UTC+2, Max Rydahl Andersen wrote:
Just to add some more info on this problem.

The problem we got is that we have a set of osgi bundles, which inside them contain different versions of a jar.
Lets call them org.fwk.runtime_1-8.0.0 and org.fwk.runtime_2-8.0.0. 

These have different bundle names, but contain jar with same classes for the tools to be able to work with multiple runtimes at a time (same situation if you had a project that would need to reach and use different jdbc versions of a database vendor)

Now we want to add tests for this using Mockito.

Mockito unfortunately *Caches* classes via name, thus it will after you have tested org.fwkruntime_1 not load org.fwkruntime_2 in its tests and we are screwed.

To fix that there are two options:
1) add mockito.jar to each and every test bundle (that doesn't scale well)

2) disable the mockito caching.


...one would think #2 would be easy but because Mockito only allow overriding of its DefaultMockitoConfiguration by creating an org.mockito.MockitoConfiguration class that is also not possible since:

a) putting that class in each test bundle will not make it seen by Mockito (since mockito wont have it is on its classpath)

b) having same package name in two different jars messes up signing jars 

Thus we need an explicit way of disable caching or/and a non-classloader dependent way of overriding Mockito's DefaultMockitoConfigruation.

This is what we are forced to right now:

and for each test that needs to disable caching we do this:

And I really would prefer not to have this custom customization exposed via org.mockito.* name space in all our eclipse projects.

Not good.

If you guys have another way of overriding this configuraiton that avoids this that would be very much appreciated.

Max Rydahl Andersen

unread,
Jun 19, 2013, 10:13:13 AM6/19/13
to moc...@googlegroups.com, enig...@googlemail.com
Anyone alive here ?

We are looking at having to fork mockito to have it working properly in with multiple versions in osgi.

Would love to not having to do that.

Any chance of this getting fixed ?

/max

Stephan Leicht Vogt

unread,
Nov 28, 2013, 4:29:54 AM11/28/13
to moc...@googlegroups.com, enig...@googlemail.com
Hi Max

Wouldn't it be possible to create a Fragment to de mockito bundle and add your overwritten MockitoConfiguration to the fragment. So mockito would see it as it is the same classpath.

Greetings
Stephan

phantomjinx

unread,
Nov 28, 2013, 6:45:35 AM11/28/13
to moc...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Stephan,

That would work fine for plugins but all our unit tests are stored in fragments, which cannot
depend on other fragments. Ensuring that such a fragment was included in the test platform along
with its host plugin is difficult and very prone to error. The inclusion of the
MockitoConfiguration class has proved a far more stable and risk-free solution.

Regards

Paul

- --
Paul Richardson

* p.g.ric...@phantomjinx.co.uk
* p.g.ric...@redhat.com
* pgrich...@linux.com
* enig...@google.mail.com
> <http://groups.google.com/group/mockito?hl=en>.
>> For more options, visit https://groups.google.com/groups/opt_out
>> <https://groups.google.com/groups/opt_out>.
>>
>>
>
>
>
> -- Szczepan Faber Principal engineer@gradleware Lead@mockito
>
> -- You received this message because you are subscribed to the Google Groups "mockito" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> mockito+u...@googlegroups.com. To post to this group, send email to moc...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mockito?hl=en
> <http://groups.google.com/group/mockito?hl=en>. For more options, visit
> https://groups.google.com/groups/opt_out <https://groups.google.com/groups/opt_out>.
>
>
>
> -- You received this message because you are subscribed to the Google Groups "mockito" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> mockito+u...@googlegroups.com. To post to this group, send email to
> moc...@googlegroups.com. Visit this group at http://groups.google.com/group/mockito. For more
> options, visit https://groups.google.com/groups/opt_out

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlKXLNQACgkQcthLMIwdEb0swwCggkmB8NMvO3wLIdgWEt+JdByv
0KMAoM61jyaxVGub5ZCvzoV1OcyEyzdl
=oW7g
-----END PGP SIGNATURE-----

Stephan Leicht Vogt

unread,
Nov 29, 2013, 4:40:10 AM11/29/13
to moc...@googlegroups.com
Hi  Paul

You're right. I wasn't thinking it through.

Thanks and greetings
Stephan
Reply all
Reply to author
Forward
0 new messages